package com.tanhua.server.controller;

import com.tanhua.server.service.BaiduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/baidu")
public class BaiduController {

    @Autowired
    private BaiduService baiduService;

//    上报地理信息
    //    1、请求方式 post
//    2、请求地址 /baidu/location
//    3、请求参数 类型application/json 请求头上有Authorization
//     Body参数  {longitude:122.121,   latitude:34.2323,addrStr:"京顺路99号"}
//    4、返回结果
    @PostMapping(value = "/location" ,name = "上报地理信息")
    public ResponseEntity location(@RequestBody Map map){
        Double longitude = (Double) map.get("longitude");
        Double latitude = (Double) map.get("latitude");
        String addrStr = (String) map.get("addrStr");

        System.out.println(longitude+"-------"+latitude+"-------"+addrStr);

        return baiduService.saveLocation(longitude,latitude,addrStr);
    }
}
